package com.ltz.flex.service;

import java.util.Date;
import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Service;

import util.DateUtil;

import com.ltz.flex.dao.UserDao;
import com.ltz.model.User;
import com.ltz.model.UserLog;

import flex.messaging.FlexContext;

@Service("userService")
public class UserService {
	
	@Resource
	private UserDao userDao;
	
	public User getUser(String userName){
		User user=userDao.getUser(userName);
		return user;
	}
	
	public void addLoginLog(User user){
		HttpServletRequest request=FlexContext.getHttpRequest();
		//添加登录日志
		if(null!=user){
			String description="用户 \""+user.getUsername()+"\" 在 " +DateUtil.formatDate(new Date()) +" 登陆系统";
			UserLog userLog=new UserLog();
			userLog.setUserip(request.getRemoteAddr());
			userLog.setTitle(user.getUsername());
			userLog.setUserid(user.getUserid());
			userLog.setDescription(description);
			userDao.add(userLog);
		}
	}
}
